package taller2.controller.listeners.GraphCreator;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JFileChooser;

import taller2.view.menus.CreatorMenus.GraphCreatorMenu;
import taller2.view.windows.CreatorWindows.GraphCreatorWindow;

public class GraphCreatorLoadButtonListener implements ActionListener{
	private GraphCreatorWindow window;
	private GraphCreatorMenu menu;
	private JFileChooser chooser;
	
	// constructor
	public GraphCreatorLoadButtonListener(GraphCreatorWindow window,GraphCreatorMenu menu){
		this.menu = menu;
		this.window = window;
		this.chooser = new JFileChooser();
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		chooser.showOpenDialog(null);
		File selectedFile2 = chooser.getSelectedFile();
		if(selectedFile2 != null){
			String path = selectedFile2.getAbsolutePath();
			window.load(path);
		}
		menu.unselectButtons();
	}

}
